package mwn.droidbus.elements;

import java.util.ArrayList;

import com.google.android.maps.GeoPoint;

/**
 * The Class Route.
 * Represents a bus route.
 */
public class Route {

	/** The route id. */
	private String routeID;
	
	/** The name.
	 * E.g. Mount Barker via Hahndorf
	 */
	private String name;
	
	/** The stops. */
	private ArrayList<BusStop> stops = null;
	
	/** The path. */
	private ArrayList<GeoPoint> path = null;
	
	/**
	 * Instantiates a new route.
	 *
	 * @param routeID the route id
	 * @param name the name
	 */
	public Route(String routeID, String name) {
		this.routeID = routeID;
		this.name = name;
		stops = new ArrayList<BusStop>();
		path = new ArrayList<GeoPoint>();
	}
	
	/**
	 * Instantiates a new route.
	 *
	 * @param routeID the route id
	 */
	public Route(String routeID) {
		this(routeID, "");
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return routeID + " " + name;
	}
	
	/**
	 * Adds the stop.
	 *
	 * @param stop the stop
	 */
	public void addStop(BusStop stop) {
		if(this.stops == null) {
			this.stops = new ArrayList<BusStop>();
		}
		this.stops.add(stop);
	}
	
	/**
	 * Adds the path point.
	 *
	 * @param point the point
	 */
	public void addPathPoint(GeoPoint point) {
		if(this.path == null) {
			this.path = new ArrayList<GeoPoint>();
		}
		this.path.add(point);
	}
	
	public void addPathPoint(double x, double y) {
		if(this.path == null) {
			this.path = new ArrayList<GeoPoint>();
		}
		this.path.add(degreesToGeoPoint(x,y));
	}
	
	public GeoPoint degreesToGeoPoint(double lat, double lon) {
		Double latitude = lat * 1000000;
		Double longitude = lon * 1000000;

		int glat = latitude.intValue();
		int glon = longitude.intValue();

		return new GeoPoint(glat,glon);
	}
	
	/**
	 * Gets the route id.
	 *
	 * @return the route id
	 */
	public String getRouteID() {
		return routeID;
	}
	
	/**
	 * Sets the route id.
	 *
	 * @param routeID the new route id
	 */
	public void setRouteID(String routeID) {
		this.routeID = routeID;
	}
	
	/**
	 * Gets the name.
	 *
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Sets the name.
	 *
	 * @param name the new name
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Gets the stops.
	 *
	 * @return the stops
	 */
	public ArrayList<BusStop> getStops() {
		return stops;
	}
	
	/**
	 * Sets the stops.
	 *
	 * @param stops the new stops
	 */
	public void setStops(ArrayList<BusStop> stops) {
		this.stops = stops;
	}
	
	/**
	 * Gets the path.
	 *
	 * @return the path
	 */
	public ArrayList<GeoPoint> getPath() {
		return path;
	}
	
	/**
	 * Sets the path.
	 *
	 * @param path the new path
	 */
	public void setPath(ArrayList<GeoPoint> path) {
		this.path = path;
	}
	
}
